﻿ <!--Copyright (c) 2016
    Isura Edirisinghe

        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.-->
<Window x:Class="Fixtures.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
        xmlns:local="clr-namespace:Fixtures"
        DataContext="{Binding RelativeSource={RelativeSource Self}}"
        Title="ICC Fixture Editor (1.4.1)" Height="590" Width="800" MinHeight="525" MinWidth="700"
        Icon="resources/Application.png">

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="DataGrid.Generic.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <local:Matches x:Key="matches"/>
            <CollectionViewSource x:Key="cvsMatches" Source="{StaticResource matches}">
            </CollectionViewSource>

            <DataTemplate x:Key="displayDateTemplate">
                <TextBlock Text="{Binding Date, StringFormat=\{0:MM/dd/yyyy\}}"/>
            </DataTemplate>
            <DataTemplate x:Key="editDateTemplate">
                <DatePicker SelectedDate="{Binding Date}"/>
            </DataTemplate>

            <Style x:Key="buttonStyle" TargetType="Button" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
                <Setter Property="Margin" Value="3"/>
                <Setter Property="Padding" Value="3"/>
            </Style>

            <!--<Style x:Key="ColumnHeaderStyle" TargetType="DataGridColumnHeader">
            <Setter Property="Height" Value="24"/>
            <Setter Property="FontSize" Value="14" />
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="ToolTip" Value="Click to sort."/>
                </Trigger>
            </Style.Triggers>
        </Style>-->
        </ResourceDictionary>       
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>

        <DockPanel Grid.Row="0" Grid.Column="0">
            
            <DockPanel HorizontalAlignment="Stretch" LastChildFill="True">
                <Image Source="resources/file.png" Width="32" Height="32" Margin="3"/>
                <TextBox Name="FilePath" Focusable="False" VerticalAlignment="Center" Margin="3" Padding="3"/>
            </DockPanel>
        </DockPanel>

        <Grid Grid.Row="1" Grid.Column="0" >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>

            <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal">
                <Button Name="OpenButton" Click="OpenButton_Click" Style="{StaticResource buttonStyle}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="resources/Open.png" Width="32" Height="32"/>
                        <Label Content="Open" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Button Name="SaveButton" Click="SaveButton_Click" Style="{StaticResource buttonStyle}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="resources/Save.png" Width="32" Height="32"/>
                        <Label Content="Save" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Button Name="AddButton" Click="AddButton_Click" Style="{StaticResource buttonStyle}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="resources/Add.png" Width="32" Height="32"/>
                        <Label Content="Add" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Button Name="RemoveButton" Click="RemoveButton_Click" Style="{StaticResource buttonStyle}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="resources/Remove.png" Width="32" Height="32"/>
                        <Label Content="Remove" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <GroupBox Header="Season" Margin="2,0,0,0" Padding="1,0,1,0">
                    <ComboBox Name="yearComboBox" SelectionChanged="Year_Selected" VerticalAlignment="Center" Width="64">
                        <ComboBoxItem IsSelected="True"></ComboBoxItem>
                        <ComboBoxItem>2012</ComboBoxItem>
                        <ComboBoxItem>2013</ComboBoxItem>
                        <ComboBoxItem>2014</ComboBoxItem>
                        <ComboBoxItem>2015</ComboBoxItem>
                        <ComboBoxItem>2016</ComboBoxItem>
                        <ComboBoxItem>2017</ComboBoxItem>
                        <ComboBoxItem>2018</ComboBoxItem>
                        <ComboBoxItem>2019</ComboBoxItem>
                        <ComboBoxItem>2020</ComboBoxItem>
                        <ComboBoxItem>2021</ComboBoxItem>
                        <ComboBoxItem>2022</ComboBoxItem>
                        <ComboBoxItem>2023</ComboBoxItem>
                        <ComboBoxItem>2024</ComboBoxItem>
                        <ComboBoxItem>2025</ComboBoxItem>
                        <ComboBoxItem>2026</ComboBoxItem>
                        <ComboBoxItem>2027</ComboBoxItem>
                        <ComboBoxItem>2028</ComboBoxItem>
                        <ComboBoxItem>2029</ComboBoxItem>
                        <ComboBoxItem>2030</ComboBoxItem>
                        <ComboBoxItem>2031</ComboBoxItem>
                        <ComboBoxItem>2032</ComboBoxItem>
                        <ComboBoxItem>2033</ComboBoxItem>
                        <ComboBoxItem>2034</ComboBoxItem>
                        <ComboBoxItem>2035</ComboBoxItem>
                        <ComboBoxItem>2036</ComboBoxItem>
                    </ComboBox>
                </GroupBox>
                <GroupBox Header="Version" Margin="10,0,0,0" Padding="1,0,1,0">
                    <ComboBox Name="versionComboBox" SelectionChanged="Version_Selected" VerticalAlignment="Center" Width="64">
                        <ComboBoxItem IsSelected="True">2016</ComboBoxItem>
                        <ComboBoxItem>2014</ComboBoxItem>
                        <ComboBoxItem>2013</ComboBoxItem>
                        <ComboBoxItem>2012</ComboBoxItem>
                    </ComboBox>
                </GroupBox>
            </StackPanel>

            <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
                <Button Name="AboutButton" Click="AboutButton_Click" Style="{StaticResource buttonStyle}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="resources/About.png" Width="32" Height="32"/>
                        <Label Content="About" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
            </StackPanel>
        </Grid>

        <DataGrid Grid.Row="2" Grid.Column="0" Background="White" 
                  Name="matchGrid"
                  ItemsSource="{Binding Source={StaticResource cvsMatches}}"
                  HorizontalScrollBarVisibility="Hidden"
                  AutoGenerateColumns="False"
                  SelectionMode="Single" SelectionUnit="FullRow"
                  CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="False"
                  CanUserSortColumns="True"
                  RowHeaderWidth="17" RowHeight="25">
            <DataGrid.Columns>
                <DataGridTextColumn 
                    Header="Id" 
                    Binding="{Binding Id}" 
                    IsReadOnly="true"
                    CellStyle="{StaticResource LeftAlignedCellStyle}"
                    MinWidth="35"/>
                <DataGridTemplateColumn
                    Header="Date"
                    CellStyle="{StaticResource LeftAlignedCellStyle}"
                    CellTemplate="{StaticResource displayDateTemplate}"
                    CellEditingTemplate="{StaticResource editDateTemplate}"
                    MinWidth="75"/>
                <DataGridComboBoxColumn
                    Header="Type"
                    SelectedItemBinding="{Binding Type, UpdateSourceTrigger=PropertyChanged}"
                    ItemsSource="{x:Static local:MatchType.Types}"
                    CellStyle="{StaticResource LeftAlignedCellStyle}"
                    MinWidth="130"/>
                <DataGridTextColumn
                    x:Name="typeCode"
                    Header="TypeCode"
                    Binding="{Binding TypeCode, StringFormat=\{0:X2\}}"
                    IsReadOnly="True"
                    Visibility="Hidden"
                    CellStyle="{StaticResource LeftAlignedCellStyle}"
                    />
                <DataGridTextColumn
                    Header="Match" 
                    Binding="{Binding MatchInSeries, UpdateSourceTrigger=PropertyChanged}" 
                    CellStyle="{StaticResource RightAlignedCellStyle}"
                    MinWidth="55"/>
                <DataGridTextColumn 
                    Header="Series" 
                    Binding="{Binding SeriesLength, UpdateSourceTrigger=PropertyChanged}" 
                    CellStyle="{StaticResource RightAlignedCellStyle}"
                    MinWidth="55"/>
                <DataGridComboBoxColumn
                    Header="Host"
                    SelectedItemBinding="{Binding HostTeam, UpdateSourceTrigger=PropertyChanged}"
                    ItemsSource="{x:Static local:Team.Teams}"
                    MinWidth="150"/>
                <DataGridTextColumn
                    x:Name="hostCode"
                    Header="HostCode"
                    Binding="{Binding HostTeamCode, StringFormat=\{0:X4\}}"
                    IsReadOnly="True"
                    Visibility="Hidden"
                    CellStyle="{StaticResource LeftAlignedCellStyle}"
                    />
                <DataGridComboBoxColumn
                    Header="Visitor"
                    SelectedItemBinding="{Binding VisitorTeam, UpdateSourceTrigger=PropertyChanged}"
                    ItemsSource="{x:Static local:Team.Teams}"
                    MinWidth="150"/>
                <DataGridTextColumn
                    x:Name="visitorCode"
                    Header="VisitorCode"
                    Binding="{Binding VisitorTeamCode, StringFormat=\{0:X4\}}"
                    IsReadOnly="True"
                    Visibility="Hidden"
                    CellStyle="{StaticResource LeftAlignedCellStyle}"
                    />
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>
